<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <title>修改产品信息</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui/css/layui.css">
    <link rel="stylesheet" href="../css/scroll-bar.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="//at.alicdn.com/t/font_693759_wytlyqhtdtj1nhfr.css">
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
</head>

<body>
<div class="ok-body">
    <!--面包屑导航区域-->
    <div class="ok-body-breadcrumb">
        <span class="layui-breadcrumb">
            <a><cite>产品信息</cite></a>
            <a><cite>添加产品</cite></a>
        </span>

    </div>
    <!--form表单-->
    <form class="layui-form ok-form">
        <br />
        <div class="layui-form-item">
            <div class="layui-userinfo">
                <table>
                    <tr>
                        <td>
                            <label class="layui-form-label">
                                产品编号
                            </label>
                            <div class="layui-input-inline">
                                <input readonly="readonly" class="productId layui-input"/>
                            </div>
                            <br />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label class="layui-form-label">
                                产品名
                            </label>
                            <div class="layui-input-inline">
                                <input type="text" class="productName layui-input"/>
                            </div>
                            <br />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label class="layui-form-label">产品数量</label>
                            <div class="layui-input-inline">
                                <input type="text" class="productNum layui-input" />
                            </div>
                            <br />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label class="layui-form-label">产品价格</label>
                            <div class="layui-input-inline">
                                <input class="productPrice layui-input" />
                            </div>
                            <br />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label class="layui-form-label">产品图片</label>
                            <div class="layui-input-inline">
                                <input  class="productImg layui-input" />
                            </div>
                            <br />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label class="layui-form-label">产品类型</label>
                            <div class="layui-input-inline">
                                <input  class="productTypeId layui-input" />
                            </div>
                            <br />
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button id="sub" class="layui-btn" >修改</button>
                <button type="reset" class="layui-btn layui-btn-primary">取消</button>
            </div>
        </div>
    </form>
</div>
<!--js逻辑-->
<script src="../lib/layui/layui.js"></script>
<script>
layui.use(['element', 'form', 'jquery', 'laydate'], function() {
    var element = layui.element;
    var table = layui.table;
    var form = layui.form;
    var $ = layui.jquery;
    var laydate = layui.laydate;

    form.verify({
        birthdayVerify: [/^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))(\s(([01]\d{1})|(2[0123])):([0-5]\d):([0-5]\d))?$/, '日期格式不正确']
    });
    form.on('submit(edit)', function(data) {
        var inputs = $("input[name=wexiu]");
        var json = [];

        for(var i = 0; i < inputs.length; i++) {
            var j = {};
            //						alert(inputs[i].value);// 等于 kk
            j.selectProduct = inputs[i].value;
            j.obj = i;
            json.push(j);

        }
        console.log(data);
        var selectProduct = JSON.stringify(json);
        console.log(selectProduct);
//					$.ajax({
//						url: "http://localhost:8080/function/addMaintenancePlan.do",
//						type: "POST",
//						datatype: "json",
//						jsonp:"callback",
//						contentType: "application/json; charset=utf-8",
//						data: {"id":data.orderId},
//						success: function(data, stats) {
//							if(stats == "success") {
//								//   window.location.href="/yc"
//							}
//						},
//						error: function(data) {
//							alert("请求失败");
//						}
//					});
        $.post("http://www.516code.cn/backstage/selectAllPro.do",selectProduct, function(res) {



        }, 'json');

        return false;

    });

    //自己写的
    $("#add").click(function() {
        var inputArray = $("input[type=text]");
        var id;

        for(var i = 0; i < inputArray.length; i++) { //循环整个input数组
            var input = inputArray[i]; //取到每一个input
            id = parseInt(input.id);
        }
        id++;
        $("table[id=tian]").append("<tr><td>" + id + ".</td><td><input name='wexiu' class='layui-input' id='" + id + "' type='text' /></td></tr>");
    });

    $("#del").click(function() {
        var trArray = $("table[id=tian]").find("tr");
        var index;
        for(var i = 0; i < trArray.length; i++) { //循环整个tr数组

            index = i;
        }
        if(index == 0) {
            index = 1;
        }
        $("table[id=tian] tr:eq(" + index + ")").remove();

    });
    $("#sub").click(function (){
        var inputs = $("input[name=wexiu]");
        var json = [];

        for(var i = 0; i < inputs.length; i++) {
            var j = {};
            //						alert(inputs[i].value);// 等于 kk
            j.selectProduct = inputs[i].value;
            j.obj = i;
            json.push(j);

        }
        console.log(json);
        var selectProduct = JSON.stringify(json);
        console.log(selectProduct);
        $.post("http://admin.516code.cn/backstage/function/InsertProduct.do",{"id":data.productId}, function(res) {



        }, 'json');
    })
})

</script>
</body>

</html>